﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AliasEnterModeForm.cs" company="TechBits">
//   Copyright (c) TechBits. All rights reserved.
// </copyright>
// <author>
//   Leandro G. Vacirca.
// </author>
// <summary>
//   Defines the AliasEnterModeForm type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace IntelliShortCut.UI.Forms
{
    using System.Windows.Forms;
    using Data;

    /// <summary>
    /// Alias Enter Mode Form.
    /// </summary>
    public partial class AliasEnterModeForm : InfoBaseForm
    {
        #region "Private Members"

        /// <summary>
        /// Saves the alias.
        /// </summary>
        private string _alias;

        #endregion

        #region "Constructors"

        /// <summary>
        /// Initializes a new instance of the <see cref="AliasEnterModeForm"/> class.
        /// </summary>
        public AliasEnterModeForm()
        {
            InitializeComponent();
            EnterMode  = ShortcutEnterModeEnum.AliasName;
        }

        #endregion

        #region "Public Properties"

        /// <summary>
        /// Gets or sets EnterMode.
        /// </summary>
        /// <value>The enter mode.</value>
        public ShortcutEnterModeEnum EnterMode { get; set; }

        #endregion

        #region "Public Methods"

        /// <summary>
        /// Show the form as modal form.
        /// </summary>
        /// <returns>
        /// The alias of the shortcut.
        /// </returns>
        public string ShowForm()
        {
            ShowDialog();
            return _alias;
        }

        #endregion

        #region "UI Events"

        /// <summary>
        /// Saves the data entered by the user when the enter key is pressed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The event parameters.</param>
        private void AliasTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode != Keys.Enter)
            {
                return;
            }

            if (string.IsNullOrEmpty(AliasTextBox.Text))
            {
                MessageBox.Show(
                    "You must enter an alias for this shortcut.",
                    "Information",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);

                return;
            }

            _alias = AliasTextBox.Text;
            AliasTextBox.Text = string.Empty;
            Close();
        }

        #endregion
    }
}